//
//  ZXCheckPicCell.m
//  BiCanStu
//
//  Created by 120v on 2018/5/16.
//  Copyright © 2018年 screson. All rights reserved.
//

#import "ZXCheckPicCell.h"

#define MaxSCale 2.0  //最大缩放比例
#define MinScale 0.5  //最小缩放比例

@interface ZXCheckPicCell ()
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *imgH;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *imgW;
@property (nonatomic,assign) CGFloat totalScale;
@property (weak, nonatomic) IBOutlet UIImageView *imgView;

@end

@implementation ZXCheckPicCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    
//    UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinch:)];
//    [self.imgView addGestureRecognizer:pinch];
//    self.imgView.userInteractionEnabled = YES;
//    self.imgView.contentMode = UIViewContentModeScaleAspectFit;
    

    
}

-(void)setPicUrl:(NSString *)picUrl {
    _picUrl = picUrl;
    
    self.totalScale = 1.0;

    [self.imgView sd_setImageWithURL:_picUrl.length!=0 ? [NSURL URLWithString:_picUrl] :nil placeholderImage:[UIImage imageNamed:@"kbylogo"] options:SDWebImageRetryFailed completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
        
        CGSize size  = image.size;
//        CGFloat w = size.width;
//        CGFloat h = size.height;
//        NSLog(@"====%f-----%f",w, h);
        if(size.width == 0){
            
            size.width = screenW;
            size.height = 200;
        }
        self.imgW.constant = screenW;
        self.imgH.constant = screenW*size.height/size.width;
        
    }];
    
}

- (void)pinch:(UIPinchGestureRecognizer *)recognizer{
    
    CGFloat scale = recognizer.scale;
    
    //放大情况
    if(scale > 1.0){
        if(self.totalScale > MaxSCale) return;
    }
    
    //缩小情况
    if (scale < 1.0) {
        if (self.totalScale < MinScale) return;
    }
    
    self.imgView.transform = CGAffineTransformScale(self.imgView.transform, scale, scale);
    self.totalScale *=scale;
    recognizer.scale = 1.0;
    
}

@end
